﻿namespace Sitecore.ChangesTracker.Commands
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using Sitecore.Shell.Framework.Commands;
  using Sitecore.Diagnostics;
  using Sitecore.Data.Items;
  using Sitecore.Globalization;
  using Sitecore.Web;

  public class cpLanguages : Command
  {
    // Methods
    public override void Execute(CommandContext context)
    {
    }
    public override string GetClick(CommandContext context, string click)
    {
      return string.Empty;
    }
    public override string GetHeader(CommandContext context, string header)
    {
      Assert.ArgumentNotNull(context, "context");
      Assert.ArgumentNotNull(header, "header");
      string lang = context.Parameters["arc_lang_cp"];
      if (!string.IsNullOrEmpty(lang))
      {
        //Item item = context.Items[0];
        System.Globalization.CultureInfo cultureInfo = Language.Parse(lang).CultureInfo;
        if (cultureInfo.IsNeutralCulture)
        {
          cultureInfo = Language.CreateSpecificCulture(cultureInfo.Name);
        }
        string englishName = cultureInfo.EnglishName;
        if (englishName.IndexOf("(") > 0)
        {
          englishName = StringUtil.Left(englishName, englishName.IndexOf("(")).Trim();
        }
        if (!string.IsNullOrEmpty(englishName))
        {
          return englishName;
        }
      }

      return base.GetIcon(context, header);
    }
    public override string GetIcon(CommandContext context, string icon)
    {
      Assert.ArgumentNotNull(context, "context");
      Assert.ArgumentNotNullOrEmpty(icon, "icon");
      string lang = WebUtil.GetSessionString("arc_lang_cp", Context.ContentLanguage.Name); //string.IsNullOrEmpty(context.Parameters["arc_lang_cp"]) ? Context.ContentLanguage.Name : context.Parameters["arc_lang_cp"];
      if (!string.IsNullOrEmpty(lang))
      {
        //Item item = context.Items[0];
        string str = LanguageService.GetIcon(Language.Parse(lang), Context.ContentDatabase);
        if (!string.IsNullOrEmpty(str))
        {
          return str;
        }
      }
      return base.GetIcon(context, icon);
    }
  }
}

